//
//  ByApiPay.m
//  itboye_shop_ios
//
//  Created by pro on 17/2/13.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByApiPay.h"

@implementation ByApiPay

// 钱包支付
+ (void)walletPay:(ByNetParamsModel *)model
          success:(void(^)(ByNetBaseResult *result))success
          failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Wallet_pay";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.pay_code forKey:@"pay_code"];
   
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** 钱包支付 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

@end
